package zhouzhouyongche.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import zhouzhouyongche.client_util.ClientTicket;
import zhouzhouyongche.client_util.Json;
import zhouzhouyongche.service.TicketService;

@Controller
@Action(value = "ticket")
public class TicketAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	@Autowired
	private TicketService ticketService;
	
	private int startCityId;
	private int startPassengerId;
	private String startTime;
	private String busNumber;
	private int endCityId;
	private int endSiteId;
	private String busType;
	private float price;
	private int inventory;
	private int year;
	private int month;
	private int day;
	
	public void getTicketes(){
		//得到余票大于0的车票信息
		List<ClientTicket> list = ticketService.getTicket(startCityId, endCityId, year, month, day);
		writeJson(list.size(), list);
	}
	
	public void addTicket() {
		Json json = new Json();
		try {
			ticketService.addTicket(startCityId, startPassengerId, endCityId, endSiteId,
					startTime, busNumber, busType, price, inventory);
			json.setSuccess(true);
			json.setMsg("添加车票成功");
		} catch (Exception e) {
			json.setSuccess(false);
			json.setMsg("添加车票失败");
		}
		
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public int getStartCityId() {
		return startCityId;
	}

	public void setStartCityId(int startCityId) {
		this.startCityId = startCityId;
	}

	public int getEndCityId() {
		return endCityId;
	}

	public void setEndCityId(int endCityId) {
		this.endCityId = endCityId;
	}

	public int getStartPassengerId() {
		return startPassengerId;
	}

	public void setStartPassengerId(int startPassengerId) {
		this.startPassengerId = startPassengerId;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getBusNumber() {
		return busNumber;
	}

	public void setBusNumber(String busNumber) {
		this.busNumber = busNumber;
	}

	public int getEndSiteId() {
		return endSiteId;
	}

	public void setEndSiteId(int endSiteId) {
		this.endSiteId = endSiteId;
	}

	public String getBusType() {
		return busType;
	}

	public void setBusType(String busType) {
		this.busType = busType;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public int getInventory() {
		return inventory;
	}

	public void setInventory(int inventory) {
		this.inventory = inventory;
	}
}
